package com.itheima.homework1.num2;


import java.util.ArrayList;

public class Test {
    public static void main(String[] args) {
        Student s1 = new Student(1,"张无忌","河北");
        Student s2 = new Student(2,"张三丰","河南");
        Student s3 = new Student(3,"赵敏","蒙古");
        Student s4 = new Student(4,"周芷若","四川");
        //创建一个集合
        ArrayList<Student> list = new ArrayList<>();
        //将学生信息添加到集合中
        list.add(s1);
        list.add(s2);
        list.add(s3);
        list.add(s4);
        //遍历集合
        for (int i = 0; i < list.size(); i++) {
            Student s = list.get(i);
            //调用String 的equals方法判断名字是否 是张三丰
            if("张三丰".equals(s.getName())){
                //利用ArrayList中的set方法修改张三丰的居住地
                Student s5 = new Student(s.getId(), s.getName(), "山东");
                list.set(i,s5);
            }
        }
        System.out.println(list);



    }
}
